//获取地址栏参数sid
var SubExceptionValid = null;
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)return  unescape(r[2]);
    return null;
}

// 调用方法
var stadiumIdValue = GetQueryString("stadiumId");
$(function () {
    /*给顶部工具条 人员管理 加上激活样式*/
    $("#SubscModule").addClass("active");
    /*根据button上的href属性跳转页面*/
    $("#SubException button").click(function (e) {
        try {
            if ($(this).attr("paramType").length > 0) {
                var selectedSubException = $("table").find(".warning");
                if ($(this).attr("paramType") == "id") {
                    window.location.href = "/" + $(this).attr("href") + "?" + $(this).attr("paramName") + "=" + selectedSubException.first().find("td").last().html();
                    return;
                } else if ($(this).attr("paramType") == "ids") {
                    insertMessageBox($("table"), "删除例外操作是不可逆的，您确认要执行此操作吗？", deleteSubException, $(this));
                    return;
                }
            }
        } catch (e) {
        }
        if (stadiumIdValue == null) {
            window.location.href = "/" + $(this).attr("href2");
        }
        else {
            window.location.href = "/" + $(this).attr("href") + "?" + "sid" + "=" + stadiumIdValue;
        }
    });

    SubExceptionValid = $("#ff").myValid();

    var btnSubmit = $("#ff").find(".controls > button:eq(0)");
    btnSubmit.bind("click", function () {
        iSubmit($("#ff"), $(this), SubExceptionValid, null, null, null);
    });

    var btnReset = $("#ff").find(".controls > button:eq(1)");
    btnReset.bind("click", function () {
        iReset($("#ff"), $(this), SubExceptionValid);
    });

    $('tbody tr').activeTable(
        function () {
            $("#SubException button:eq(1)").removeAttr("disabled");
            $("#SubException button:eq(2)").removeAttr("disabled");
        },
        function () {
            $("#SubException button:eq(1)").attr("disabled", "disabled");
            $("#SubException button:eq(2)").attr("disabled", "disabled");
        });
    $(".table-bordered tbody td").fillEmptyCell();
    $("table").trCheckboxToCenter();
    $(".panel").panelBodyToggle();
});
function deleteSubException(obj) {
    var selectedSubException = $("table").find(".warning");
    var ids = [];
    ids[0] = "int";
    selectedSubException.each(function (i) {
        var id = $(this).find("td").last().html();
        ids[++i] = id;
    });
    var data = obj.attr("paramName") + "=" + arrayToJson(ids);
    iAjaxPost(obj.attr("href"), data, function () {
        window.location.href = obj.attr("href2") + "?stadiumId=" + stadiumIdValue;
    }, $(this), $(".table"));
}